package com.construction_Safety.region.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.construction_Safety.common.annotation.Log;
import com.construction_Safety.common.core.controller.BaseController;
import com.construction_Safety.common.core.domain.AjaxResult;
import com.construction_Safety.common.enums.BusinessType;
import com.construction_Safety.region.domain.CRegion;
import com.construction_Safety.region.service.ICRegionService;
import com.construction_Safety.common.utils.poi.ExcelUtil;

/**
 * 区域信息管理Controller
 * 
 * @author yat
 * @date 2025-06-09
 */
@RestController
@RequestMapping("/region/region")
public class CRegionController extends BaseController
{
    @Autowired
    private ICRegionService cRegionService;

    /**
     * 查询区域信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('region:region:list')")
    @GetMapping("/list")
    public AjaxResult list(CRegion cRegion)
    {
        List<CRegion> list = cRegionService.selectCRegionList(cRegion);
        return success(list);
    }

    /**
     * 导出区域信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('region:region:export')")
    @Log(title = "区域信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CRegion cRegion)
    {
        List<CRegion> list = cRegionService.selectCRegionList(cRegion);
        ExcelUtil<CRegion> util = new ExcelUtil<CRegion>(CRegion.class);
        util.exportExcel(response, list, "区域信息管理数据");
    }

    /**
     * 获取区域信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('region:region:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cRegionService.selectCRegionById(id));
    }

    /**
     * 新增区域信息管理
     */
    @PreAuthorize("@ss.hasPermi('region:region:add')")
    @Log(title = "区域信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CRegion cRegion)
    {
        return toAjax(cRegionService.insertCRegion(cRegion));
    }

    /**
     * 修改区域信息管理
     */
    @PreAuthorize("@ss.hasPermi('region:region:edit')")
    @Log(title = "区域信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CRegion cRegion)
    {
        return toAjax(cRegionService.updateCRegion(cRegion));
    }

    /**
     * 删除区域信息管理
     */
    @PreAuthorize("@ss.hasPermi('region:region:remove')")
    @Log(title = "区域信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cRegionService.deleteCRegionByIds(ids));
    }

    /**
     * 无需HTTP映射的内部调用方法：将所有区域状态设置为待维修(1)
     */
    public AjaxResult resetAllRegionsToPendingRepair()
    {
        int rows = cRegionService.updateAllRegionStatus(1);
        return toAjax(rows);
    }
}
